package com.orhon.smartcampus.modules.systemctl.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Where;

import com.orhon.smartcampus.modules.base.entity.Schools;

import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
//@EqualsAndHashCode
@Entity
@Table(name = "systemctl_modules", schema = "smartcloud", catalog = "")
//@Where(clause = "deletedAt=null")
public class Modules {


    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Long id;

    @Column(name = "module_name", nullable = true)
    private String moduleName;
    
    @Column(name = "category", nullable = true, length = 191)
    private String category;
    
    @Column(name = "module_order", nullable = true)
    private Integer moduleOrder;
    
    @Column(name = "mark", nullable = true, length = 255)
    private String mark;
    
    @Column(name = "clients", nullable = true)
    private String clients;
    
    @Column(name = "status", nullable = true)
    private Integer status;
    
    @Column(name = "icon", nullable = true, length = 255)
    private String icon;
    
    @Column(name = "meta", nullable = true)
    private String meta;
    
    @Column(name = "created_at", nullable = true)
    private Date createdAt;
    
    @Column(name = "updated_at", nullable = true)
    private Date updatedAt;
    
    @Column(name = "deleted_at", nullable = true)
    private Date deletedAt;

    @Transient
    @Column(name = "home_id", nullable = true)
    private Integer home_id;

    @OneToOne( cascade = CascadeType.ALL , fetch = FetchType.LAZY)
    @Where(clause = "ISNULL(deleted_at)")
    @JoinColumn(name = "home_id")
    @NotFound(action=NotFoundAction.IGNORE)
    private Menus home;
    
    
    @OneToMany( cascade = CascadeType.ALL , fetch = FetchType.LAZY)
  	@JoinColumn(name = "module_id")
    @Where(clause = "ISNULL(deleted_at)")
  	@NotFound(action=NotFoundAction.IGNORE)
  	List<Menus> menus;
    //
  	@OneToMany( cascade = CascadeType.ALL , fetch = FetchType.LAZY)
  	@Where(clause = "ISNULL(deleted_at)")
  	@JoinColumn(name = "module_id")
  	@NotFound(action=NotFoundAction.IGNORE)
  	List<Widgets> widgets;
  	
  	@ManyToMany( cascade = CascadeType.ALL , fetch = FetchType.LAZY)
    @Where(clause = "ISNULL(deleted_at)")
	@JoinTable(name = "systemctl_modules_school_relations",
	joinColumns = { @JoinColumn(name = "module_id")}, 
	inverseJoinColumns = { @JoinColumn(name = "school_id")})
  	List<Schools> schools;

    @OneToMany( cascade = CascadeType.ALL , fetch = FetchType.LAZY)
    @Where(clause = "ISNULL(deleted_at)")
    @JoinColumn(name = "module_id")
    @NotFound(action=NotFoundAction.IGNORE)
    List<Operations> oprations;

    @OneToMany( cascade = CascadeType.ALL , fetch = FetchType.LAZY)
    @Where(clause = "ISNULL(deleted_at)")
    @JoinColumn(name = "module_id")
    @NotFound(action=NotFoundAction.IGNORE)
    List<Apis> apis;
  	
    
    
    

}
